<style type="text/css">
#l-map{height:300px;width:100%;}
#r-result{width:100%;}
</style>
<div ng-show="pagedata.isshow==0" ng-include="sys_html('_menu')"></div>
<div ng-show="pagedata.isshow==0" class="fui-page order-create-page fui-page-current">
	<div class="fui-content  navbar">
		<div id="l-map"></div>
		<div class="weui_cells" style="margin:2%">
			<div class="weui_noborder" style="margin-top:6px;margin-bottom:-5px;color:#646464;font-size:10px">在这里上车</div>
			<div class="weui_noborder" id="r-result">
				<div class="weui_cell_hd green-spot" style="padding:0"></div>
				<div class="weui_cell_bd weui_cell_primary"><input id="address" ng-click="pagedata.isshow=1;pagedata.type=1" class="weui_input" ng-model="pagedata.info.start_seat" type="text"  placeholder=""></div>
			</div>
			<div class="weui_cell" id="r-result">
				<div class="weui_cell_hd f60-spot" style="padding:0"></div>
				<div class="weui_cell_bd weui_cell_primary" ng-click="pagedata.isshow=1;pagedata.type=2" ><input readonly="readonly" type="text" class="weui_input" ng-model="pagedata.info.dest_seat"  id="suggestId" size="20" value="百度" placeholder="你要去哪儿"/></div>
			</div>
			<div ng-show="pagedata.show2==0" class="weui_btn_all" style="background:#333" href="javascript:" ng-click="post(pagedata.info,'create')">确定行程</div>
		</div>
		<div class="weui_cells" style="margin:2%" ng-show="pagedata.show2==1">
			<div class="fui-menu-group">
				<a class="fui-menu-item" style="color: #f60;"><i class="fa fa-cloud" style="color: {{menu.iconcolor}};"></i> 现在出发</a>
				<a class="fui-menu-item" style="color: {{menu.textcolor}};" href="javascript:;" onclick="changeuser()"><i class="fa fa-cloud" style="color: {{menu.iconcolor}};"></i> 换乘坐人</a>
			</div>
			<div class="fui-icon-group noborder col-3">
                <a class="fui-icon-col external" href="">
					<div class="text" style="color: #666666;">行程距离</div>
                    <div class="icon"><i class="icon jinyunicon icon-ditu"/></div>
                    <div class="text" style="color: #F60;">{{pagedata.info.juli}}</div>
                </a>
                <a class="fui-icon-col external" href="">
					<div class="text" style="color: #666666;">预计时间</div>
                    <div class="icon"><i class="icon jinyunicon icon-shijian"/></div>
                     <div class="text" style="color: #F60;">{{pagedata.info.time}}</div>
                </a>
                <a class="fui-icon-col external" href="" data-nocache="true">
					<div class="text" style="color: #666666;">预计价格</div>
                    <div class="icon"><i class="icon jinyunicon icon-goumai"/></div>
                    <div class="text" style="color: #F60;">￥{{pagedata.info.price1}}元</div>
                </a>
			</div>
			<div class="weui_btn_all" style="background:#333" href="javascript:" ng-click="post(pagedata.info,'create')">立即叫车</div>
		</div>
		<!--<div class="weui_cells">
			<div class="weui_cell" id="r-result">
				<div class="weui_cell_bd weui_cell_primary">距离:</div>
				<div class="weui_cell_ft">{{pagedata.info.juli}}</div>
			</div>
			<div class="weui_cell" id="time">
				<div class="weui_cell_bd weui_cell_primary">时间:</div>
				<div class="weui_cell_ft">{{pagedata.info.time}}</div>
			</div>
			<div class="weui_cell" id="price">
				<div class="weui_cell_bd weui_cell_primary">预计价格:</div>
				<div class="weui_cell_ft">{{pagedata.info.price1}}</div>
			</div>
		</div>
		<div id="r-result">	<input style="display:none;" disabled="disabled" id="lat" ng-model="pagedata.info.lat" type="text"  placeholder=""></div>
		<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
		<div class="weui_btn_area" >
				 <a class="weui_btn weui_btn_primary" href="javascript:" id="showTooltips" ng-click="post(pagedata.info,'create')">叫车</a>
		</div>-->
	</div>
</div>
<div id="changeuser" class="modal fade" tabindex="-1" style="z-index: 99999; display: none;">
	<div class="modal-dialog" style="width:94%;top:30%;left:3%;">
			<div class="modal-content" style="border-radius: 4px;padding:0.5rem 0" >
				<div aria-hidden="true" data-dismiss="modal" class="closebtn"><i class="icon jinyunicon icon-wrong"></i></div>
				<div class="weui_cells weui_cells_form">
							  <div class="weui_cell weui_vcode">
								<div class="weui_cell_hd"><label class="weui_label">姓名</label></div>
								<div class="weui_cell_bd weui_cell_primary">
									<input class="weui_input" type="text" ng-model="pagedata.member.name" placeholder="请输入您的真实姓名">
								</div>
							</div>
							<div class="weui_cell weui_vcode">
								<div class="weui_cell_hd"><label class="weui_label">手机</label></div>
								<div class="weui_cell_bd weui_cell_primary">
									<input class="weui_input" type="text" ng-model="pagedata.member.mobile" placeholder="请输入您的手机号码">
								</div>
							</div>
				</div>
				<div class="weui_btn_area">
						 <a class="weui_btn weui_btn_333" aria-hidden="true" data-dismiss="modal" href="javascript:" id="showTooltips" ng-click="pagedata.info.mobile=pagedata.member.mobile;pagedata.info.name=pagedata.member.name;">提交</a>
				</div>
			</div>
	</div>
</div>
<div ng-show="pagedata.isshow ==1">
<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>	
<div id="l-map"></div>
<div id="allmap"></div>
<div class="fui-page  fui-page-current page-goods-list">
<div class="fui-header">
		<div class="fui-header-left">
			<span ng-show="pagedata.pcd.district" style="font-size:0.65rem">{{pagedata.pcd.district}}</span>
			<span ng-show="!pagedata.pcd.district" style="font-size:0.65rem">{{pagedata.pcd.city || '广州市'}}</span>
			<!--<i class="icon jinyunicon icon-moreunfold"></i>-->
		</div>
		<div class="title">
			<form method="post">
					<div class="searchbar searchbar-active" style="margin-left:2.2rem">
					<div class="search-input">
						<input type="search" id="search" ng-model="pagedata.dizhi" placeholder="你要去哪儿..." value="">
					</div>
					</div>
			</form>
		</div>
		<div class="fui-header-right" ng-click="pagedata.isshow = 0">确定</div>
</div>
<div ng-show="pagedata.showarea !=1" class="fui-content" style="margin-top:2.3rem">
		<div class="weui_cells" style="margin:2%">
			<div class="weui_cell" id="r-result" ng-repeat="item in pagedata.history">
				<div class="weui_cell_hd icon jinyunicon icon-ditu"></div>
				<div class="weui_cell_bd weui_cell_primary"  ng-click="pagedata.dizhi=item.address;pagedata.hlat=item.lat_lng;history()" >
					<span style="float:left;width:100%;">{{item.address}}</span>
					<span style="float:left;font-size:0.55rem;color:#646464">{{item.pcd}}</span>
				</div>
			</div>
		</div>
		
</div>
<div class="fui-content" style="top:1.3rem" ng-show="pagedata.showarea ==1">
		<div class="weui_cells weui_cells_access">
				<a class="weui_cell" href="javascript:;">
					<div class="weui_cell_bd weui_cell_primary" style="padding:0">
						<span>当前定位/选择地区：{{pagedata.pcd.city || '广州市'}}</span>
					</div>
					<div class="weui_cell_ft" ng-click="toogle(post,'show')">
						选择县区
					</div>
				</a>
				<div class="row margin0" ng-show="post.show">
						<div class="jy-3" ng-repeat="value in pagedata.province[pagedata.pcd.province][pagedata.pcd.city]">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea(pagedata.pcd.province,pagedata.pcd.city,value);pagedata.showarea = 0;">
									<div>{{value}}</div>
									<div class="clear"></div>
							</div>
						</div>
				</div>
			</div>
			<div class="weui_cells_title">热门地区</div>
			<div class="weui_cells">
				<div class="row margin0">
					<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('广东省','深圳市','');pagedata.showarea = 0;">
									<div>深圳市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('上海市','上海市','');pagedata.showarea = 0;">
									<div>上海市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('广东省','东莞市','');pagedata.showarea = 0;">
									<div>东莞市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('北京市','北京市','');pagedata.showarea = 0;">
									<div>北京市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('江苏省','南京市','');pagedata.showarea = 0;">
									<div>南京市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('江苏省','杭州市','');pagedata.showarea = 0;">
									<div>杭州市</div>
									<div class="clear"></div>
							</div>
						</div>
				</div>
			</div>
			<div ng-repeat="(value,data) in pagedata.province">
				<div class="weui_cells_title">{{value}}</div>
				<div class="weui_cells">
					<div class="row margin0">
						<div class="jy-3" ng-repeat="(city,data) in pagedata.province[value]">
								<div class="yuyue-duan" style="width:auto" ng-click="selectarea(value,city,'');pagedata.showarea = 0;">
										<div>{{city}}</div>
										<div class="clear"></div>
								</div>
						</div>
					</div>
				</div>
		    </div>
</div>
</div>
</div>

<script type="text/javascript">
scope.pagedata.showarea =0;
scope.pagedata.isshow =0;
	//百度地图API功能

if(scope.pagedata.info.start_seat==null){
if(scope.pagedata.info.lat==null){
	window.scope.location(function(res){
		if(!scope.pagedata.pcd.city){
				scope.pagedata.pcd.province = res.addressComponents.province;
				scope.pagedata.pcd.city = res.addressComponents.city;
		}
		require(['map'], function(BMap){
		var map = new BMap.Map("l-map");
		
		
		var point = new BMap.Point(res.lat_lng.lng,res.lat_lng.lat);
		map.centerAndZoom(point, 12);
		var marker = new BMap.Marker(point);  // 创建标注
		map.addOverlay(marker);  
		});
			scope.pagedata.info.start_seat = res.address;
			scope.pagedata.info.lat = res.lat_lng;
			scope.$evalAsync();
		
	});
}
scope.selectarea = function(province,city,district){
	//scope.$apply(function(){
		scope.pagedata.pcd.province = province;
		scope.pagedata.pcd.city = city;
		scope.pagedata.pcd.district = district;
	//});
}
if(scope.pagedata.info.lat!=null){
	require(['map'], function(BMap){
		var map = new BMap.Map("l-map");
		var point = new BMap.Point(scope.pagedata.info.lat.lng,scope.pagedata.info.lat.lat);
		map.centerAndZoom(point, 12);
		var marker = new BMap.Marker(point);  // 创建标注
		map.addOverlay(marker);  
		var pt = new BMap.Point(scope.pagedata.info.lat.lng,scope.pagedata.info.lat.lat);
		//map.centerAndZoom(point,12);
		var geoc = new BMap.Geocoder();    
			geoc.getLocation(pt, function(rs){
				var addComp = rs.addressComponents;
				var address= addComp.province  + addComp.city + addComp.district  + addComp.street  + addComp.streetNumber;
				scope.pagedata.info.start_seat = address;
				scope.$evalAsync();
			});        
		}); 
	}
}

scope.history=function(){
if(scope.pagedata.type==1){
			scope.pagedata.info.start_seat=scope.pagedata.dizhi;
			scope.pagedata.info.slat=scope.pagedata.hlat;
			$('#address').val(scope.pagedata.dizhi);
			scope.pagedata.show=0;
	if(scope.pagedata.info.dest_seat!=null){
		require(['map'], function(BMap){
				var map = new BMap.Map("l-map");	
				var searchComplete = function (results){
					if (transit.getStatus() != BMAP_STATUS_SUCCESS){
						return ;
					}
				var plan = results.getPlan(0);
					
					//scope.$apply(function(){
						//scope.pagedata.show=0;
						scope.pagedata.show2=1;			
						//scope.pagedata.info.dest_seat = myValue;
						scope.pagedata.info.time = plan.getDuration(true);
						//$('#time').val( plan.getDuration(true));
						scope.pagedata.info.juli = plan.getDistance(true);
						//$('#juli').val(plan.getDistance(true));
						var juli= plan.getDistance(true).substr(0, plan.getDistance(true).length - 2); 
						if(parseInt(juli) > parseInt(scope.pagedata.item.juli)){
						
						scope.pagedata.info.price1 = Math.ceil(juli-scope.pagedata.item.juli)*scope.pagedata.item.price1+parseInt(scope.pagedata.item.start);
						
						}else{
						scope.pagedata.info.price1 = parseInt(scope.pagedata.item.start);
						}
						//$('#price1').val(scope.pagedata.info.price1);
						scope.$apply();
						}
					var transit = new BMap.DrivingRoute(map, {renderOptions: {map: map},
					onSearchComplete: searchComplete,
					onPolylinesSet: function(){        
					//setTimeout(function(){alert(output)},"1000");
				}});
				//var address = $("#address").val();
				//var p1 = new BMap.Point(scope.pagedata.info.lat.lng,scope.pagedata.info.lat.lat);  
				transit.search(scope.pagedata.info.start_seat,scope.pagedata.info.dest_seat);	
		});
	}
}else{
			scope.pagedata.info.dest_seat=scope.pagedata.dizhi;
			scope.pagedata.info.dlat=scope.pagedata.hlat;
			$('#suggestId').val(scope.pagedata.dizhi);
			scope.pagedata.show=0;
require(['map'], function(BMap){
	var map = new BMap.Map("l-map");	
	var searchComplete = function (results){
		if (transit.getStatus() != BMAP_STATUS_SUCCESS){
			return ;
		}
	var plan = results.getPlan(0);
		
		//scope.$apply(function(){
			//scope.pagedata.show=0;
			scope.pagedata.show2=1;			
			//scope.pagedata.info.dest_seat = myValue;
			scope.pagedata.info.time = plan.getDuration(true);
			//$('#time').val( plan.getDuration(true));
			scope.pagedata.info.juli = plan.getDistance(true);
			//$('#juli').val(plan.getDistance(true));
			var juli= plan.getDistance(true).substr(0, plan.getDistance(true).length - 2); 
			if(parseInt(juli) > parseInt(scope.pagedata.item.juli)){
			
			scope.pagedata.info.price1 = (juli-scope.pagedata.item.juli)*scope.pagedata.item.price1+parseInt(scope.pagedata.item.start);
			}else{
			scope.pagedata.info.price1 = parseInt(scope.pagedata.item.start);
			}
			//$('#price1').val(scope.pagedata.info.price1);
			scope.$apply();
		//});			
	}	
	var transit = new BMap.DrivingRoute(map, {renderOptions: {map: map},
		onSearchComplete: searchComplete,
		onPolylinesSet: function(){        
		//setTimeout(function(){alert(output)},"1000");
	}});
	//var address = $("#address").val();
	//var p1 = new BMap.Point(scope.pagedata.info.lat.lng,scope.pagedata.info.lat.lat);  
      
		
	transit.search(scope.pagedata.info.start_seat,scope.pagedata.info.dest_seat);	
	});
}
	//$('#time').val( plan.getDuration(true));
	//$('#juli').val(plan.getDistance(true));
	//$('#price1').val(scope.pagedata.info.price1);
	scope.pagedata.show2=1;	
}

function G(id) {
		return document.getElementById(id);
}
window.HOST_TYPE = "2"; window.BMap_loadScriptTime = (new Date).getTime();
require(['map'], function(BMap){
	var map = new BMap.Map("l-map");
	if(scope.pagedata.item.city != ''){
		var city = scope.pagedata.item.city;
	}else{
		var city = "北京";
	}
	
	//var point = new BMap.Point(116.331398,39.897445);
	//map.centerAndZoom(point, 15);
	//var marker = new BMap.Marker(point);  // 创建标注
	//map.addOverlay(marker);               // 将标注添加到地图中
	
	map.centerAndZoom(city,12);                   // 初始化地图,设置城市和地图级别。
	//map.addOverlay(scope.pagedata.info.lat.lat,scope.pagedata.info.lat.lng); 
	var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
		{"input" : "search"
		,"location" : map
	});
	
	ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
	var str = "";
		var _value = e.fromitem.value;
		var value = "";
		if (e.fromitem.index > -1) {
			value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
		}    
		str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
		value = "";
		if (e.toitem.index > -1) {
			_value = e.toitem.value;
			value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
		}    
		str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
		G("searchResultPanel").innerHTML = str;
	});
	

	var myValue;
	ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
	var _value = e.item.value;
		myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
		G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;		
		
		if(scope.pagedata.type==1){
			setPlace1();
		}else{
			setPlace();
		}
		
	});
	function setPlace1(){
	
		//map.clearOverlays();    //清除地图上所有覆盖物
		function myFun(){
			var pp = local.getResults().getPoi(0).point;			//获取第一个智能搜索的结果
			scope.$apply(function(){
			scope.pagedata.isshow=0;
			scope.pagedata.info.start_seat = myValue;
			scope.pagedata.info.start_lat = pp;			
		});
		var params = {
					'plugin':'jy_taxi',
					'action':'index',
					'op':'history',
					'data':{'address' : myValue,'lat_lng' : pp,
					'pcd':local.getResults().getPoi(0).address,},
					'callback':function(data){
							
							if(data == 'success'){
									
							}
					}
		}
		scope.post_json(params);
	map.centerAndZoom(pp, 18);
	if(scope.pagedata.info.dest_seat!=null){
	var searchComplete = function (results){
		if (transit.getStatus() != BMAP_STATUS_SUCCESS){
			return ;
		}
		var plan = results.getPlan(0);
		
		scope.$apply(function(){
			scope.pagedata.isshow=0;
			scope.pagedata.show2=1;
			//scope.pagedata.info.dest_seat = myValue;
			scope.pagedata.info.time = plan.getDuration(true);
			scope.pagedata.info.juli = plan.getDistance(true);
			var dw=plan.getDistance(true).substr(plan.getDistance(true).length-1,1);
			if(dw=='里'){
				var juli= parseFloat(scope.pagedata.info.juli); 
				if(juli > scope.pagedata.item.juli){
				
				scope.pagedata.info.price1 = (juli-scope.pagedata.item.juli)*scope.pagedata.item.price1+scope.pagedata.item.start;
				}else{
				scope.pagedata.info.price1 = scope.pagedata.item.start;
				}
			}else{
				scope.pagedata.info.price1 = scope.pagedata.item.start;
			}
			
		});
		
		//output += plan.getDuration(true) + "\n";                //获取时间
		//output += "总路程为：" ;
		//output += plan.getDistance(true) + "\n";             //获取距离
	}
	var transit = new BMap.DrivingRoute(map, {renderOptions: {map: map},
		onSearchComplete: searchComplete,
		onPolylinesSet: function(){        
		//setTimeout(function(){alert(output)},"1000");
	}});
	//var address = $("#address").val();
		//var p1 = new BMap.Point(scope.pagedata.info.lat.lng,scope.pagedata.info.lat.lat);  
      
		
	transit.search(pp,scope.pagedata.info.dlat);
	}
		
		}
		var local = new BMap.LocalSearch(map, { //智能搜索
		  onSearchComplete: myFun
		});
				
		local.search(myValue);
	}
	function setPlace(){
		
		map.clearOverlays();    //清除地图上所有覆盖物
		function myFun(){
			var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
			map.centerAndZoom(pp, 18);
			
				// 百度地图API功能
			//map.addOverlay(scope.pagedata.info.lat.lat,scope.pagedata.info.lat.lng);    //添加标注
		//var output = "大约所需时间为";
	var searchComplete = function (results){
		if (transit.getStatus() != BMAP_STATUS_SUCCESS){
			return ;
		}
		var plan = results.getPlan(0);
		
		scope.$apply(function(){
			scope.pagedata.isshow=0;
			scope.pagedata.show2=1;
			scope.pagedata.info.dest_seat = myValue;
			scope.pagedata.info.dest_lat = pp;		
			scope.pagedata.info.time = plan.getDuration(true);
			scope.pagedata.info.juli = plan.getDistance(true);
			var juli= plan.getDistance(true).substr(0, plan.getDistance(true).length - 2); 
			if(parseInt(juli) > parseInt(scope.pagedata.item.juli)){
			
			scope.pagedata.info.price1 = (juli-scope.pagedata.item.juli)*scope.pagedata.item.price1+parseInt(scope.pagedata.item.start);
			}else{
			scope.pagedata.info.price1 = parseInt(scope.pagedata.item.start);
			}
			
		});
		var params = {
					'plugin':'jy_taxi',
					'action':'index',
					'op':'history',
					'data':{
					'address' : myValue,
					'lat_lng' : pp,
					'pcd':local.getResults().getPoi(0).address,
					},
					'callback':function(data){
							
							if(data == 'success'){
									
							}
					}
		}
		scope.post_json(params);
		//output += plan.getDuration(true) + "\n";                //获取时间
		//output += "总路程为：" ;
		//output += plan.getDistance(true) + "\n";             //获取距离
	}
	var transit = new BMap.DrivingRoute(map, {renderOptions: {map: map},
		onSearchComplete: searchComplete,
		onPolylinesSet: function(){        
		//setTimeout(function(){alert(output)},"1000");
	}});
	//var address = $("#address").val();
		var p1 = new BMap.Point(scope.pagedata.info.lat.lng,scope.pagedata.info.lat.lat);  
      
		
	transit.search(p1,pp);
			
		}
		var local = new BMap.LocalSearch(map, { //智能搜索
		  onSearchComplete: myFun
		});
		local.search(myValue);
	}
	
});
function myhome(){
	var params = {
					'plugin':'jy_taxi',
					'action':'home',
					'callback':function(data){
						if(data.error !=1){
							scope.pagedata.member = data.member
							scope.$apply();
						}else{
							alert(data.msg);
						}
					}
			}
	scope.post_json(params);
	$('#myhome').modal();
}
function changeuser(){
	
	$('#changeuser').modal();
}


</script>
